public class Logic {
    public String userName = "zhangsan";//设置初始账号名字为：zhangsan
    public String password = "123456";//初始密码为1234456

    public void  loginInfo(String userName,String password) throws UerNameException {
        //该方法用来验证密码是否正确,参数为
        //比较用户名
        if(!this.userName.equals(userName)) {
            //System.out.println("用户名错误！");
            throw new UerNameException("用户名错误！");//抛出异常
        }
        //比较密码
        if(!this.password.equals(password)) {
            //System.out.println("密码错误！");
            throw new PassWordException("密码错误！");//抛出异常
        }
    }

    public static void main(String[] args) {
        try {
            Logic logic = new Logic();
            logic.loginInfo("zhangsan","6666");//调用方法输入账号和密码
        } catch (PassWordException e) {
            e.printStackTrace();
        } catch (UerNameException e) {
            //throw new RuntimeException(e);
        }
        System.out.println("捕获异常后，不影响代码继续往下执行!");
    }
}
